<!DOCTYPE html>
<html>
<head>    
	<title>edit</title>	
	<include file='public/head'>	
		<style>		
			.layui-legend-size{font-size:14px !important;}		
			.layui-nopadding{padding:0 !important;}		
			.layui-overflow{overflow:auto;}		
			.layui-nomargin{margin: 0 !important;}		
			.layui-bottom{border-bottom:1px solid rgb(226, 226, 226);}		
			.layui-input{height:30px !important; }		
			.layui-form-search-item 
			.layui-inline{margin-bottom: 5px;} 		
			.layui-form-search-item label{margin-left: 15px;}		
			.layui-table-page {padding: 7px 0px 0px;}		
			.layui-field-padding{border-width: 1px;padding:0 0 5px 10px;}	
		</style>
	</head>
	<body>	
		<div class="layui-tab " lay-filter="demo-tab">	
		<div class="layui-tab-nav" >        
			<ul class="layui-tab-title">			
				<li style="padding: 0;">
					<a href="{:cmf_plugin_url('Goods://admin_index/index')}" style="padding:0 15px;">退出</a>
				</li>			
				<li style="padding: 0;" class="layui-this">
					<a style="padding:0 15px;" href="">修改商品</a>
				</li>		
			</ul>	
		</div>	
		<form class="layui-form" id="f" style="margin-top:20px"  method="post">		
			<div id="steps" ></div>		
			<div id="fff">			
<!-- 				<php>				
					foreach ($chai as $key => $value) {		            
						if ($key == 0) {		            	
						$html = '<div id="'.'ss-'.$key.'">'.$value.'</div>';		        	
					} else {		        		
						$html = '<div style="display:none;" id="'.'ss-'.$key.'">'.$value.'</div>';		        	
					}		        	
					echo $html;		        
					}			
				</php> -->
				<php>
					$html = '';
					foreach ($chai as $key => $value) {

			            if ($key == 0) {

							$html .= '<div id="'.'ss-'.$key.'">'.$value.'</div>';

			        	}

			        	if($key == 1){
			        		$html .= '<div style="display:none;" id="'.'ss-'.$key.'">'.$value;
			        	}

			        	if($key == 2){
			        		$html .= $value.'</div>';
			        	}

			        	if($key == 3){
			        		$key = 2;
			        		$html .= '<div style="display:none;" id="'.'ss-'.$key.'">'.$value.'</div>';
			        	}
			        }
			        echo $html;
				</php>						
			</div>		
			<div class="layui-form-item">			
				<div class="layui-input-block" id="btns">			
				</div>		
			</div>	
		</form>
	</div>
	<include file='public/scripts'>
  <script type="text/javascript">
	$(function(){	
		layer = layui.layer;
		form = layui.form;	
		chai = {:json_encode($chai)};	
		num = (chai.length)-2;	
		// var html = '<div id="'+'ss-0">'+chai[0]+'</div>';	
		// $('#fff').append($(html));	
		$('#btns').html('<button type="button" class="layui-btn" onclick="nextStep()">下一步</button>');
		form.render();	
		layui.extend({ 		
			steps: '__STATIC__/js/layui-v2.5.5/extends/steps/steps' 	
		});	
		layui.use('steps', function () {	    
			var steps = layui.steps;	   	
			var da = [];	    
			for (var i = 0; i < chai.length-1; i++) {	    	
				da[i] = {'title': "第"+(i+1)+"步"};	    
			}	    
			steps.render({	        
				ele: '#steps',	        
				data: da, 
				//desc 不是必须	        
				current:  0//默认为第几步	    
			});	
		});
	})

	//下一步
	function nextStep() {	
		var current = layui.steps.current;	
		if (current > num) {		
			return false;	
		}	
		if ( current == 1 )
		{
			if($('#goods_name').val() == ''){
				layer.msg('商品名称不能为空',{icon:2,time:1500});
				return false;
			}
			if($('#n-goods_img').val() == ''){
				layer.msg('商品主图不能为空',{icon:2,time:1500});
				return false;
			}
		}
		
		layui.steps.next();	
		var current = layui.steps.current;	
		var ss = $('#ss-'+current).html();	
		$('#ss-'+(current-1)).hide();	
		if (ss == null) {		
			var html = '<div id="'+'ss-'+current+'">'+chai[current]+'</div>';		
			$('#fff').append($(html));	
		} else {		
			$('#ss-'+current).show();	
		}	
		if (current == num) {		
			$('#btns').html('<button type="button" class="layui-btn" onclick="lastStep()">上一步</button><button type="button" class="layui-btn" onclick="subss()" id="subs">立即提交</button>');	
		}else if (current < num) {		
			$('#btns').html('<button type="button" class="layui-btn" onclick="lastStep()">上一步</button><button type="button" class="layui-btn" onclick="nextStep()">下一步</button>');	
		}	
		form.render();
	}
	//上一步
	function lastStep(){	
		var current = layui.steps.current;	
		if (current == 0) {		
			return false;	
		}	
		$('#ss-'+current).hide();	
		$('#ss-'+(current-1)).show();	
		layui.steps.last();	form.render();	
		if ((current-1) == 0) {		
			$('#btns').html('<button type="button" class="layui-btn" onclick="nextStep()">下一步</button>');	
		} else if ( (current-1) < num ) {		
			$('#btns').html('<button type="button" class="layui-btn" onclick="lastStep()">上一步</button><button type="button" class="layui-btn" onclick="nextStep()">下一步</button>');	
		}
	}
</script>
<script type="text/javascript">
	function subss(){	
		var da = $('#f').serialize();	
		tijiao(da);	return false;
	}

	var tijiao = function(da){	
		$.ajax({		
			url:"{:cmf_plugin_url('Goods://admin_index/editGoods')}",		
			data: da,		
			type:'post',		
			success:function(data){			
			if (data.code == 1) {				
				layer.msg(data.msg,{icon:1,time:1500},function(){					
					window.location.href = "{:cmf_plugin_url('Goods://admin_index/index')}";				
				});			
			} else {				
				layer.msg(data.msg,{icon:2,time:1500});			
			}		
		},		
			error:function()		
			{			
				layer.msg('系统错误',{icon:2,time:1500});		
			}	
		})
	}
</script>
</body>
</html>